Skip to content

[k2] add metrics builder and k2_write_metric API#1639

Open
denisichh wants to merge 12 commits into
masterfrom
dzubarev/common-logs-api-k2kphp
Open

[k2] add metrics builder and k2_write_metric API#1639
denisichh wants to merge 12 commits into
masterfrom
dzubarev/common-logs-api-k2kphp

Conversation

@denisichh

Copy link
Copy Markdown
Contributor

No description provided.

@denisichh denisichh self-assigned this Jun 21, 2026
@denisichh denisichh added runtime Feature related to runtime k2 Affects compiler or runtime in K2 mode labels Jun 21, 2026
Comment thread runtime-light/k2-platform/k2-header.h Outdated
* <COUNT_MASK><f64> - count value
* <INC_MASK> - counter increment (no payload)
*/
enum MetricValueMask : uint32_t { VALUE_MASK = 0, VALUES_ARRAY_MASK = 1, COUNT_MASK = 2, INC_MASK = 3 };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. What does 0 mean here?
  2. Maybe rename to MetricKind?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread runtime-light/k2-platform/k2-header.h
Comment thread runtime-light/k2-platform/k2-header.h Outdated
* @param `buf_len` The length of the serialized metric data in bytes.
* @param `ms` The target monitoring system.
*/
void k2_write_metric(const uint8_t* buf, size_t buf_len, enum MonitoringSystem ms);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The interface looks like an error is possible, but you never return it
  2. Do we need buf to be uint8_t*? Why is void* not enough?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread runtime-light/k2-platform/k2-api.h Outdated
return {};
}

inline void write_metric(const kphp::stl::vector<uint8_t, kphp::memory::script_allocator>& serialized_metric, k2::MonitoringSystem ms) noexcept {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need vector here. std::span is enough

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


struct MetricBuilder final : vk::movable_only {
private:
using bytes_vector = kphp::stl::vector<uint8_t, kphp::memory::script_allocator>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::byte instead of uint8_t?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

#include "runtime-common/core/std/containers.h"
#include "runtime-light/k2-platform/k2-api.h"

struct MetricBuilder final : vk::movable_only {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put it in kphp::diagnostics namespace as kphp::diagnostics::metric_builder

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use snake case for types (except *State for now)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


struct MetricBuilder final : vk::movable_only {
private:
using bytes_vector = kphp::stl::vector<uint8_t, kphp::memory::script_allocator>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks a bit weird that you use private type in public API of MetricBuilder

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

private:
using bytes_vector = kphp::stl::vector<uint8_t, kphp::memory::script_allocator>;

std::string metric_name;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't use std::string as it uses malloc internally. Let's replace with kphp::stl::string

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

k2 Affects compiler or runtime in K2 mode runtime Feature related to runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants